﻿using PRO.DbProvider;
using PRO.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PRO.ORM;
using System.Data;
using System.Data.Common;
using PRO.Common;

namespace PRO.Data.SqlServer
{
    public partial class DataProvider : IDataProvider
    {
        public int CreateCashCoupon(CashCouponInfo info)
        {
            string sql = "SELECT count(id) FROM Pro_CashCoupon where CardNumber=@CardNumber";
            DbParameter[] prams = {
									 DbHelper.MakeInParam("@CardNumber",(DbType)SqlDbType.NVarChar,14,info.CardNumber)
								   };
            if (DbHelper.ExecuteScalar(CommandType.Text, sql, prams).ToString().ToInt(0) == 0)
            {
                return info.Insert();
            }
            else
                return 0;
        }
        public bool SetSoldOver(int id)
        {
            string sql = "update Pro_CashCoupon set status=1 where status=0 and id=" + id;
            return Convert.ToBoolean(DbHelper.ExecuteNonQuery(CommandType.Text, sql));
        }
        public bool DelCashCoupon(int id)
        {
            string sql = "delete Pro_CashCoupon where status=0 and id=" + id;
            return Convert.ToBoolean(DbHelper.ExecuteNonQuery(CommandType.Text, sql));
        }
        public DataTable GetCashCoupon(string number)
        {
            string sql = "SELECT id,cardnumber,cashprice,status,createtime,usetime  FROM Pro_CashCoupon where status=1 and CardNumber=@CardNumber";
            DbParameter[] prams = {
									 DbHelper.MakeInParam("@CardNumber",(DbType)SqlDbType.NVarChar,12,number)
								   };
            return DbHelper.ExecuteDataset(CommandType.Text, sql, prams).Tables[0];
        }
    }
}
